package com.project.service.base.CrpData;

import com.project.common.utils.Util;
import com.project.service.base.cryptolib.CryptoApp;


import java.io.UnsupportedEncodingException;


/**
 * author: WheelChen
 * date: 2017/7/18
 *
 * 加密基本属性
 */
public class CryBaseData {

    static byte[] key = {0x01, 0x23, 0x45, 0x67, (byte) 0x89, (byte) 0xab, (byte) 0xcd, (byte) 0xef,
            (byte) 0xfe, (byte) 0xdc, (byte) 0xba, (byte) 0x98, 0x76, 0x54, 0x32, 0x10};
    static byte[] iv = {0x01, 0x23, 0x45, 0x67, (byte) 0x89, (byte) 0xab, (byte) 0xcd, (byte) 0xef,
            (byte) 0xfe, (byte) 0xdc, (byte) 0xba, (byte) 0x98, 0x76, 0x54, 0x32, 0x10};

    /**
     * author: WheelChen
     * date: 2017/7/18
     * function: 加密字符串
     *
     * @param pText String
     * @return
     */
    public String encry(String pText) throws Exception {
        byte[] ctext = CryptoApp.SM4Enc(pText, key, iv);
        return Util.bytesToHexString(ctext);
    }

    /**
     * author: WheelChen
     * date: 2017/7/19
     * function: 解密字符串
     *
     * @param cText String
     * @return
     */
    String dec(String cText) throws UnsupportedEncodingException {
        return CryptoApp.SM4Dec(Util.hexStringToBytes(cText), key, iv);
    }


}
